package Day2025_03_31;

public class LeetCode98 {
    long prev = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if (root == null) return true;
        boolean left = isValidBST(root.left);
        if (!left) return false;
        boolean cur = false;
        if (root.val > prev) cur = true;
        prev = root.val;
        if (!cur) return false;
        boolean right = isValidBST(root.right);
        return left && right && cur;
    }
}
